package com.ynny.librarysystemmanager.cronserver;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.ynny.librarysystemmanager.common.BookStatus;
import com.ynny.librarysystemmanager.entity.Record;
import com.ynny.librarysystemmanager.mapper.RecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


import java.util.List;

@Component
public class BookCronServer {

    @Autowired
    RecordMapper recordMapper;

    @Scheduled(cron = "0 0 0 * * ?")
    public void checkRecordOverdue(){
        //检查图书是否逾期
        List<Record> records = recordMapper.selectRecordsLessEndTime();

        for (Record record : records) {

            record.setStatus(BookStatus.Overdue.getCode());
            int i = recordMapper.updateRecord(record);

            System.out.println(i);


        }


    }
}
